#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QAction>
#include<Image.h>
#include<Matrix.h>
#include<iostream>
#include<QByteArray>
#include<QPixmap>
#include<QDebug>
#include <QFileInfo>
using namespace  std;


QString File;
QString File2;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //设置信号，点击那个open可以出现选项
    connect(ui->actionopen,&QAction::triggered,[=](){
        //打开的文件用filename 保存下来
   QString filename= QFileDialog::getOpenFileName(this,"选择图片;",QCoreApplication::applicationFilePath());
    //if successfully open
 //   qDebug()<<filename;
    File=filename;
  //  qDebug()<<File;
   if(filename.isEmpty()){
       QMessageBox::warning(this,"提示","请选择一张图");
   }

// 显示到屏幕
   QPixmap pix (filename);
   ui->label->setPixmap(pix);
    });

    //*******************************
    connect(ui->actionopen_3,&QAction::triggered,[=](){
   QString filename2= QFileDialog::getOpenFileName(this,"选择图片;",QCoreApplication::applicationFilePath());
    File2=filename2;

   if(filename2.isEmpty()){
       QMessageBox::warning(this,"提示","请选择一张图");
   }
});



}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::on_pushButton_clicked()
{
       cout<<"hello world"<<endl;   // debug
       qDebug()<<File;

       //
        char*  ch;
       QByteArray ba = File.toLatin1(); // must
       ch=ba.data();
       qDebug()<<ch;
       //

       Image ima(ch);
       ima.Flip(1);
       ima.WriteBMP("UpDown.bmp");

       QString file2="UpDown.bmp";
               qDebug()<<file2;
      //QString filename ="D:\\qt file\\project3\\UpDown.bmp";// *******
       QImage* img=new QImage; //   **********
       if(! ( img->load(file2) ) ) //加载图像
       {
           delete img;
           return;
       }
       QPixmap pix (file2);
        ui->label_2->setPixmap(pix);

        //
       cout<<"success!"<<endl;
       //

}

void MainWindow::on_pushButton_2_clicked()
{
   // cout<<"hello"<<endl;
    //

    char*  ch;
   QByteArray ba = File.toLatin1(); // must
   ch=ba.data();
    //

   Image imj(ch);
       imj.Transpose();
       imj.WriteBMP("transpose.bmp");

       QString file2="transpose.bmp";
       QImage* img=new QImage; //   **********
       if(! ( img->load(file2) ) ) //加载图像
       {
           delete img;
           return;
       }
       QPixmap pix (file2);
        ui->label_2->setPixmap(pix);


}

void MainWindow::on_pushButton_3_clicked()
{
    char*  ch;
    char* ch2;
    QByteArray ba = File.toLatin1();
   QByteArray ba2 = File2.toLatin1(); // must
   ch=ba.data();
   ch2=ba2.data();
//
    Image iml(ch);
        Image imm(ch2);
        Image imn(Sub(iml, imm));
        imn.bitmapinfoheader = iml.bitmapinfoheader;
        imn.bmpfileheader = iml.bmpfileheader;
        imn.WriteBMP("sub.bmp");

        QString file3="sub.bmp";
        QImage* img=new QImage; //   **********
        if(! ( img->load(file3) ) ) //加载图像
        {
            delete img;
            return;
        }
        QPixmap pix (file3);
         ui->label_2->setPixmap(pix);


}

void MainWindow::on_pushButton_4_clicked()
{   //
    char*  ch;
   QByteArray ba = File.toLatin1(); // must
   ch=ba.data();
    //
    Image imd(ch);
        imd.Resize(10, 20);
        imd.WriteBMP("small.bmp");
        //
        QString file2="small.bmp";
        //
        QImage* img=new QImage; //   **********
        if(! ( img->load(file2) ) ) //加载图像
        {
            delete img;
            return;
        }
        QPixmap pix (file2);
         ui->label_2->setPixmap(pix);
}

void MainWindow::on_pushButton_5_clicked()
{
    char*  ch;
   QByteArray ba = File.toLatin1(); // must
   ch=ba.data();

     Image ima(ch);
    ima.Warm(ch);
     QString file2="Copy.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);

}

void MainWindow::on_pushButton_6_clicked()
{
    char*  ch;
   QByteArray ba = File.toLatin1(); // must
   ch=ba.data();

     Image ima(ch);
    ima.cold(ch);
     QString file2="Copy.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);
}
